package com.example.tuike.mapper;

import com.example.tuike.entity.Platforms;
import org.apache.ibatis.annotations.*;

import java.util.List;

/*** @Author supersaiya
 * @Description TODO

 * @Date 2025/1/29 20:11

 * @Version 1.0*/
@Mapper // 标记为 MyBatis 的 Mapper 接口
public interface PlatformsMapper {

    // 插入平台（返回自增主键）
    @Insert("INSERT INTO platforms (name, url) VALUES (#{name}, #{url})")
    @Options(useGeneratedKeys = true, keyProperty = "platformId") // 获取自增主键
    void insert(Platforms platform);

    // 根据 ID 查询平台
    @Select("SELECT * FROM platforms WHERE platformId = #{platformId}")
    Platforms findById(Integer platformId);

    // 更新平台信息
    @Update("UPDATE platforms SET name = #{name}, url = #{url} WHERE platformId = #{platformId}")
    void update(Platforms platform);

    // 删除平台
    @Delete("DELETE FROM platforms WHERE platformId = #{platformId}")
    void delete(Integer platformId);

    // 查询所有平台（可选：分页）
    @Select("SELECT * FROM platforms")
    List<Platforms> findAll();
}
